@page "/Configurations/LiveLotteryTaskConfig"
@using Microsoft.AspNetCore.Authorization
@using Ray.BiliBiliTool.Config.Options;
@attribute [Authorize]
@rendermode InteractiveServer
@inherits BaseConfigComponent<LiveLotteryTaskOptions>

<PageTitle>直播抽奖任务配置</PageTitle>

<MudContainer>
    <MudText Typo="Typo.h4" Class="mb-4">直播抽奖任务配置</MudText>

    @if (_isLoading)
    {
        <MudProgressCircular Color="Color.Primary" Indeterminate="true" />
    }
    else
    {
        <EditForm Model="@_config" OnValidSubmit="HandleValidSubmitAsync">
            <DataAnnotationsValidator />

            <!-- 基础配置卡片 -->
            <MudCard Class="mb-4">
                <MudCardHeader>
                    <CardHeaderContent>
                        <MudText Typo="Typo.h6">基础配置</MudText>
                    </CardHeaderContent>
                </MudCardHeader>
                <MudCardContent>
                    <MudGrid>
                        <MudItem xs="12" md="6">
                            <MudSwitch T="bool" @bind-Value="_config.IsEnable"
                                Label="启用任务" Color="Color.Primary" />
                        </MudItem>
                        <MudItem xs="12" md="6">
                            <MudTextField T="string" @bind-Value="_config.Cron" Label="定时任务Cron表达式"
                                HelperText="例如：0 0 22 * * ? (每天晚上10点执行)"
                                Disabled="!_config.IsEnable" />
                        </MudItem>
                    </MudGrid>
                </MudCardContent>
            </MudCard>

            <!-- 详细配置卡片 -->
            @if (_config.IsEnable)
            {
                <MudCard>
                    <MudCardHeader>
                        <CardHeaderContent>
                            <MudText Typo="Typo.h6">详细配置</MudText>
                        </CardHeaderContent>
                    </MudCardHeader>
                    <MudCardContent>
                        <MudGrid>
                            <MudItem xs="12" md="6">
                                <MudTextField T="string" @bind-Value="_config.ExcludeAwardNames" Label="排除的奖品名称关键字"
                                    HelperText="根据关键字排除包含这些文字的奖品名称，多个用|分隔" />

                                <MudTextField T="string" @bind-Value="_config.IncludeAwardNames" Label="包含的奖品名称关键字" Class="mt-3"
                                    HelperText="根据关键字指定奖品名称必须包含的文字，多个用|分隔" />

                                <MudSwitch T="bool" @bind-Value="_config.AutoGroupFollowings"
                                    Label="抽奖结束后是否自动将关注的主播分组到天选时刻分组" Color="Color.Primary" Class="mt-3" />
                            </MudItem>

                            <MudItem xs="12" md="6">
                                <MudTextField T="string" @bind-Value="_config.DenyUids" Label="主播Uid黑名单"
                                    HelperText="一般是中奖后的老赖，多个用英文逗号分隔，配置后不会参加黑名单中的主播的抽奖活动" />
                            </MudItem>
                        </MudGrid>
                    </MudCardContent>
                </MudCard>
            }

            <!-- 操作按钮 -->
            <MudCard Class="mt-4">
                <MudCardActions>
                    <MudButton ButtonType="ButtonType.Submit" Variant="Variant.Filled" Color="Color.Primary">保存配置</MudButton>
                    <MudButton Variant="Variant.Outlined" Color="Color.Secondary" OnClick="LoadConfigAsync" Class="ml-2">重新加载</MudButton>
                </MudCardActions>
            </MudCard>
        </EditForm>

        @if (_saveMessage.HasValue)
        {
            <MudAlert Severity="@(_saveSuccess ? Severity.Success : Severity.Error)" Class="mt-3">
                @_saveMessage
            </MudAlert>
        }
    }
</MudContainer>

<MudThemeProvider/>
<MudPopoverProvider/>
<MudDialogProvider/>
<MudSnackbarProvider/>
